package com.xjaq.dify.interceptor;

import com.github.lianjiatech.retrofit.spring.boot.interceptor.BasePathMatchInterceptor;
import com.xjaq.dify.config.DiFyConfig;
import lombok.extern.slf4j.Slf4j;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Slf4j
public class AudioInterceptor extends BasePathMatchInterceptor {
    @Autowired
    private DiFyConfig diFyConfig;
    @Override
    protected Response doIntercept(Chain chain) throws IOException {
        Request request = chain.request();
        Request build = request.newBuilder()
                .addHeader("Authorization", "Bearer " + diFyConfig.getApiKey())
                .addHeader("Content-Type", "audio/wav")
                .addHeader("Accept", "text/event-stream")
                .addHeader("Host", diFyConfig.getHost())
                .build();
        return chain.proceed(build);
    }
}
